package org.file5.domain;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.file5.util.UUIDUtil;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.NotSaved;
/**
 * Support relation: 
 *     - Proudct2Category
 *     - Person2Site
 * @author Conan
 *
 */
@Cached
public class Entity2Entity<E extends BaseEntity,E2 extends BaseEntity> extends BaseEntity  {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3601521800391206496L;



	private Key<E> entityKey;
	@NotSaved 
	E entity;
	private Relation relation ;
	private Key<E2>  entity2Key;
	@NotSaved 
	E2 entity2;

	//holding business data of Entity2Entity2,the meaning of the xdata is up-to you
	private String adata;
	private String bdata;
	private String cdata;
	private String ddata;
	private String edata;
	private String fdata;
	private String gdata;
	private String hdata;
	private String idata;
	private String jdata;
	
	public Entity2Entity() {
		this.setUid(UUIDUtil.getRandomUUID());
	}

	public Entity2Entity(Class<E> entityClass,E entity,Entity2Entity.Relation relation,Class<E2> entity2Class,E2 entity2){
		this.entityKey  = new Key<E>(entityClass,entity.getUid());
		this.relation = relation;
		this.entity2Key = new Key<E2>(entity2Class,entity2.getUid());
		this.setUid(UUIDUtil.getRandomUUID());
	}

 
	public Relation getRelation() {
		return relation;
	}

	public void setRelation(Relation relation) {
		this.relation = relation;
	}
 

	public Key<E> getEntityKey() {
		return entityKey;
	}



	public void setEntityKey(Key<E> entityKey) {
		this.entityKey = entityKey;
	}



	public E getEntity() {
		return entity;
	}



	public void setEntity(E entity) {
		this.entity = entity;
	}



	public Key<E2> getEntity2Key() {
		return entity2Key;
	}



	public void setEntity2Key(Key<E2> entity2Key) {
		this.entity2Key = entity2Key;
	}



	public E2 getEntity2() {
		return entity2;
	}



	public void setEntity2(E2 entity2) {
		this.entity2 = entity2;
	}



	public String getAdata() {
		return adata;
	}

	public void setAdata(String adata) {
		this.adata = adata;
	}

	public String getBdata() {
		return bdata;
	}

	public void setBdata(String bdata) {
		this.bdata = bdata;
	}

	public String getCdata() {
		return cdata;
	}

	public void setCdata(String cdata) {
		this.cdata = cdata;
	}

	public String getDdata() {
		return ddata;
	}

	public void setDdata(String ddata) {
		this.ddata = ddata;
	}

	public String getEdata() {
		return edata;
	}

	public void setEdata(String edata) {
		this.edata = edata;
	}

	public String getFdata() {
		return fdata;
	}

	public void setFdata(String fdata) {
		this.fdata = fdata;
	}

	public String getGdata() {
		return gdata;
	}

	public void setGdata(String gdata) {
		this.gdata = gdata;
	}

	public String getHdata() {
		return hdata;
	}

	public void setHdata(String hdata) {
		this.hdata = hdata;
	}

	public String getIdata() {
		return idata;
	}

	public void setIdata(String idata) {
		this.idata = idata;
	}

	public String getJdata() {
		return jdata;
	}

	public void setJdata(String jdata) {
		this.jdata = jdata;
	}


	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}


	public static enum Relation {

		// ------------------------------------------------------------------------------------------------------------------
		ARTICLE_IS_CATEGORY_MEMBER,//(  "Article is the categor's member"), // -------------------------------------------------
		PERSON_IS_SITE_MANAGER,//(  "Person is the site's manager"), // -------------------------------------------------
		SITE_IS_SITE2_BUDDY,//(  "Person is the site's manager"), // -------------------------------------------------
		
	}

}
